package com.ctshk.sapp.finance.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.bill.BillListDTO;
import com.ctshk.rpc.finance.dto.onaccount.OnAccountApplyDetailDTO;
import com.ctshk.rpc.finance.dto.onaccount.OnAccountDetailDTO;
import com.ctshk.rpc.finance.dto.onaccount.OnAccountDetailListDTO;
import com.ctshk.rpc.finance.dto.onaccount.OnAccountListDTO;
import com.ctshk.rpc.finance.req.bill.BillListReq;
import com.ctshk.rpc.finance.req.bill.RollBackReq;
import com.ctshk.rpc.finance.req.onaccount.*;
import com.ctshk.rpc.finance.service.IFinanceOnAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 财务挂账信息 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-30
 */
@RestController
@Api(value = "财务挂账", tags = "财务挂账")
@RequestMapping("/finance-on-account")
public class FinanceOnAccountController extends BaseController {

    @DubboReference
    private IFinanceOnAccountService onAccountService;


    @ApiOperation(value = "列表", notes = "列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "财务挂账-列表", operDesc = "财务挂账-列表")
    @PostMapping("/list")
    public Result<PageResponse<OnAccountListDTO>> list(@RequestBody @Valid OnAccountListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.list(req);
    }

    @ApiOperation(value = "申请挂账", notes = "申请挂账（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "财务挂账-申请挂账", operDesc = "财务挂账-申请挂账")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid OnAccountAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.add(req);
    }

    @ApiOperation(value = "挂账详情", notes = "挂账详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "财务挂账-挂账详情", operDesc = "财务挂账-挂账详情")
    @PostMapping("/detail")
    public Result<OnAccountDetailDTO> detail(@RequestBody @Valid OnAccountDetailReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.detail(req);
    }

    @ApiOperation(value = "挂账申请详情", notes = "挂账申请详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "财务挂账-挂账申请详情", operDesc = "财务挂账-挂账申请详情")
    @PostMapping("/apply-detail")
    public Result<OnAccountApplyDetailDTO> applyDetail(@RequestBody @Valid OnAccountApplyDetailReq req) {
        return onAccountService.applyDetail(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "财务挂账-审批", operDesc = "财务挂账-审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid OnAccountApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.approval(req);
    }

    @ApiOperation(value = "选择挂账明细列表", notes = "申请销账-选择挂账明细列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "财务挂账-申请销账-选择挂账明细列表", operDesc = "财务挂账-申请销账-选择挂账明细列表")
    @PostMapping("/detail-list")
    public Result<PageResponse<OnAccountDetailListDTO>> detailList(@RequestBody @Valid OnAccountDetailListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.detailList(req);
    }

    @ApiOperation(value = "撤回审批", notes = "撤回审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "撤回申请预收款审批", operDesc = "撤回申请预收款审批")
    @PostMapping("/roll-back")
    public Result rollBack(@RequestBody @Valid RollBackReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return onAccountService.rollBack(req);
    }

}
